package com.rjgc.title.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rjgc.title.mapper.LearningSociologyMapper;
import com.rjgc.title.model.entity.student.LearningExperience;
import com.rjgc.title.model.entity.user.LearningSociology;
import com.rjgc.title.service.LearningSociologyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 担任学术团队职务或社会兼职 服务实现类
 * </p>
 *
 * @author 卓抱抱
 * @since 2022-04-25
 */
@Service
public class LearningSociologyServiceImpl extends ServiceImpl<LearningSociologyMapper, LearningSociology> implements LearningSociologyService {

    @Autowired
    private LearningSociologyMapper learningSociologyMapper;

    @Override
    public LearningSociology getByUserId(String userId) {
        QueryWrapper<LearningSociology> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId);

        LearningSociology learningSociology = learningSociologyMapper.selectOne(queryWrapper);
        return learningSociology;
    }

    /**
     * 保存或者更新
     * @param learningSociology
     */
    @Override
    public void saveLearningSociology(LearningSociology learningSociology) {
        if (learningSociology.getId() != null) {
            // 更新
            learningSociologyMapper.updateById(learningSociology);
        } else {
            // 保存
            learningSociologyMapper.insert(learningSociology);
        }
    }
}
